/*  -*- mode: c++; coding: utf-8; c-file-style: "stroustrup"; -*-

    Copyright 2008 Asier Aguirre <asier.aguirre@gmail.com>
    This file is part of Intromit.

    Intromit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Intromit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Intromit.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef RENDER_ATTR_HH
#define RENDER_ATTR_HH
//! \addtogroup introsight_framework
//@{

// INCLUDES
#include "util.hh"
#include "refcnt.hh"
#include "introsight.hh"

// DEFINES
#define RA_CONVERT_TO_UCHAR(f)  ((f)>=1.0?255:((f)<0?0:(unsigned char)((f)*255.0)))
#define RA_CONVERT_TO_FLOAT(uc) ((float)(uc)*(1.0/255.0))

class render_attr: public reference_counter
{
    // PRIVATE METHODS
    void ctor();
    void dtor();

public:
    render_attr();
    virtual ~render_attr();

    bool init();
};

class render_color_anim
{
    unsigned char color[IS_RGBA];
    unsigned char color_dest[IS_RGBA];
    int start_time;
    int duration;

    // PRIVATE METHODS
    void ctor();
    void dtor();

public:
    render_color_anim();
    ~render_color_anim();

    void set_color(unsigned char color[IS_RGBA]);
    void set_color(float color_red, float color_green, float color_blue, float color_alpha);
    void set_color_dest(unsigned char color[IS_RGBA], int duration_usec);
    void set_color_dest(float color_red, float color_green, float color_blue, float color_alpha, int duration_usec);

    // returns true if requires more steps
    bool refresh(unsigned char result[IS_RGBA]);
    bool refresh(float result[IS_RGBA]);

    // util
    static inline void init_color(float c[IS_RGBA], float r, float g, float b, float a) {c[0]=r; c[1]=g; c[2]=b; c[3]=a;}
    static inline void init_color(unsigned char c[IS_RGBA], float r, float g, float b, float a)
    {
	c[IS_RED]  =RA_CONVERT_TO_UCHAR(r);
	c[IS_GREEN]=RA_CONVERT_TO_UCHAR(g);
	c[IS_BLUE] =RA_CONVERT_TO_UCHAR(b);
	c[IS_ALPHA]=RA_CONVERT_TO_UCHAR(a);
    }
};

//@}
#endif

/* Offline metadata attributes:

   @metadata_attrs(
	render_attr
	{
		# members
		:
						select, read_only

		# methods
		init:
						select
	}

	render_color_anim
	{
		# members
		color, color_dest,
		duration:
						select, read_only

		# methods
		:
						select
	}
   )
*/
